﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Client
{
    class ZXGModel
    {
        public string name { get; private set; }
        public string[] stocksArray
        {
            get
            {
                var l = stocksString.Split(',');
                if (l.Length == 1 && l[0] == "")
                    return new string[0];
                return l;
            }
        }
        public string stocksString { get; private set; }

        public ZXGModel(string name, string stocks)
        {
            this.name = name;
            stocksString = stocks;
        }

        public bool AddStock(string symbol)
        {
            if (!Exist(symbol))
            {
                if (stocksString != "")
                    stocksString += ",";
                stocksString += symbol;
                return true;
            }

            return false;
        }

        public bool RemoveStock(string symbol)
        {
            bool successful = false;
            string temp = "";
            foreach(string i in stocksArray)
            {
                if (i != symbol)
                {
                    if (temp != "")
                        temp += ",";
                    temp += i;
                }
                else
                {
                    successful = true;
                }
            }
            stocksString = temp;
            return successful;
        }

        public void RenameKind(string kindName)
        {
            name = kindName;
        }

        public bool Exist(string symbol)
        {
            bool s = false;
            foreach(string i in stocksArray)
            {
                if (i == symbol)
                    s = true;
            }
            if (!s)
                return false;
            return true;
        }
    }
}
